# 封装验证码接口
import requests


class LoginApi:
  @classmethod
  def verify_code(cls, session):
    verify_code_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=verify"
    session.get(url=verify_code_url)

  # 封装登录接口
  @classmethod
  def login(cls, session, login_body):
    login_url = "http://hmshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
    login_header = {"Content-Type": "application/x-www-form-urlencoded"}
    login_resp = session.post(url=login_url, headers=login_header, data=login_body)
    return login_resp


if __name__ == '__main__':
  session = requests.session()
  LoginApi.verify_code(session)
  login_body = {"username": "13012345678", "password": "123456", "verify_code": "8888"}
  res = LoginApi.login(session, login_body)
  print(res.json())
